﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Interface;
using System.IO;
using DevExpress.XtraEditors.Controls;
using System.Runtime.InteropServices;
using System.Reflection;

namespace Lamex.mTools.UI
{
    public partial class frmTL_Image_Brower : frmBaseChild
    {
        List<string> lst = null;
        List<ImageList> imageList = null;
        public static Form fm = null;
        public static string strPic;
        public static int X, Y;
        int zoomStep = 75;      //缩放步长
        Point mouseDownPoint = new Point(); //记录拖拽过程鼠标位置
        bool isMove = false;    //判断鼠标在picturebox上移动时，是否处于拖拽过程(鼠标左键是否按下)
        Bitmap myBmp;//图片定义
        [DllImport("gdi32.dll")]
        static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
        [DllImport("gdi32.dll")]
        static public extern IntPtr CreateDC(string driverName, string deviceName, string output, IntPtr lpinitData);
        [DllImport("gdi32.dll")]
        static public extern bool DeleteDC(IntPtr DC);

        public frmTL_Image_Brower()
        {
            InitializeComponent();
            this.Load += (s, e) =>
            {
                ControlEvent();
            };

            this.panelImage.MouseWheel += new MouseEventHandler(panelImage_MouseWheel);
            this.imageSlider1.MouseWheel += new MouseEventHandler(imageSlider1_MouseWheel);
            this.imageSlider1.LayoutMode = DevExpress.Utils.Drawing.ImageLayoutMode.ZoomInside;
        }

        private void frmTL_Image_Brower_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理

            layoutView1.CardMinSize = new System.Drawing.Size(33, 21);//图片最大化技巧：将此值设为足够小
            layoutView1.OptionsBehavior.Editable = false;
            layoutView1.OptionsCustomization.AllowFilter = false;
            layoutView1.OptionsCustomization.AllowSort = false;
            layoutView1.OptionsView.ShowCardBorderIfCaptionHidden = false;
            layoutView1.OptionsView.ShowCardCaption = false;
            layoutView1.OptionsView.ShowCardLines = false;
            layoutView1.OptionsView.ShowHeaderPanel = false;
            layoutView1.OptionsView.ViewMode = DevExpress.XtraGrid.Views.Layout.LayoutViewMode.Column;
            int height=panelImage.Height;
            imageSlider1.Images.Clear();
            //this.imageSlider1.Images.Add(Image.FromFile(@"D:\Temp\IMG_20170624_210704.jpg"));
        }

        private void frmTL_Image_Brower_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Width - 210;
        }

        #region 控件的委托事件

        /// <summary>
        /// 控件的委托事件
        /// </summary>
        private void ControlEvent()
        {
            /*卡片的点击事件*/
            this.layoutView1.CardClick += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                    this.imageSlider1.CurrentImageIndex = e.Card.RowHandle;
            };

            this.sbtnFirst.Click += (s, e) =>
            {
                //imageDisplayAdjust(imageSlider1);
                this.imageSlider1.SlideFirst();
            };
            this.sbtnPrev.Click += (s, e) =>
            {
                //imageDisplayAdjust(imageSlider1);
                this.imageSlider1.SlidePrev();
            };
            this.sbtnNext.Click += (s, e) =>
            {
                //imageDisplayAdjust(imageSlider1);
                this.imageSlider1.SlideNext();
            };
            this.sbtnLast.Click += (s, e) =>
            {
                //imageDisplayAdjust(imageSlider1);
                this.imageSlider1.SlideLast();
            };

            this.sbtnDownload.Click += (s, e) =>
            {
                var path = (string)this.layoutView1.GetRowCellValue(this.imageSlider1.CurrentImageIndex, "Paths");
                var name = this.layoutView1.GetRowCellValue(this.imageSlider1.CurrentImageIndex, "Name");

                SaveFileDialog sf = new SaveFileDialog();
                sf.Title = "选择保存文件路径";
                //sf.Filter = "图像文件(*.jpg)|*.jpg;";
                sf.Filter = "图像文件(*.png)|*.png;";
                sf.FileName = name.ToString();
                sf.AddExtension = true;/*自动添加扩展名*/
                if (sf.ShowDialog() == DialogResult.OK)
                {
                    File.Copy(path, sf.FileName, true);//目录重命名见下面代码
                }
            };
        }

        #endregion

        //获取图纸浏览路径
        private void sbtnGetPath_Click(object sender, EventArgs e)
        {
            //清除【类别及列表】数据
            cboxSearchType.Text = "";
            mtxtSeach_List.Text = "";

            XtraFolderBrowserDialog folder = new XtraFolderBrowserDialog();
            FolderBrowserDialog fb = new FolderBrowserDialog();
            //设置默认根目录是桌面
            folder.RootFolder = Environment.SpecialFolder.Desktop;
            folder.SelectedPath = @"D:\Temp";//用绝对路径时不能正确指向
            //设置对话框说明
            folder.Description = "请选择文件搜索路径:";
            if (folder.ShowDialog() == DialogResult.OK)
            {
                int width = gridControl1.Width;
                layoutView1.CardMinSize = new Size(width, 180);

                txtSearch_Path.Text = folder.SelectedPath;

                //gridControlDataBinding_WholePath();
            }
        }
      
        //To Do ......，查图过程
        private void sbtnView_Click(object sender, EventArgs e)
        {
            try
            {
                //1、首先清空[gridControl1]及[imageSlider1]数据
                gridControl1.DataSource = null;
                imageSlider1.ImageList = null;

                if (mtxtSeach_List.Text == "")
                {
                    MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                    DialogResult dr = MessageBox.Show("查询信息为空！" + "\r\n" + "如图库文件较多，继续查询有可能时间较长", "是否继续查询？", messButton);
                    if (dr == DialogResult.Cancel)//如果点击“取消”按钮，退出图片浏览
                    {
                        return;
                    }
                }
                lst = new List<string>();
                string Path = txtSearch_Path.Text.ToString();

                //2、查找符合条件的[JPG、TIF]图片文件，并加载到layoutView1中
                //var files = new DirectoryInfo(path).GetFiles().Where(p => p.Extension.ToLower() == ".jpg");
                //var files = new DirectoryInfo(path).GetFiles().Where(p => p.Name.ToLower().Contains("3960480580"));
                //var files = new DirectoryInfo(path).GetFiles();
                //var data = files.Select(d =>
                //{
                //    return new { Name = d.Name, Image = Image.FromFile(d.FullName), Paths = d.FullName };
                //});
                this.gridControl1.DataSource = null;
                if (!string.IsNullOrEmpty(mtxtSeach_List.Text))
                {
                    if (mtxtSeach_List.Text.ToString().Contains("\r\n"))
                    {
                        string[] strArray = mtxtSeach_List.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                        if (strArray.Count() != 0)
                        {
                            foreach (string s in strArray)
                            {
                                lst.Add(s);
                            }
                        }
                    }
                    else
                    {
                        lst.Add(mtxtSeach_List.Text);
                    }
                }
                var files = new DirectoryInfo(txtSearch_Path.Text).GetFiles().Where(p => (p.Extension.ToLower() == ".jpg" || p.Extension.ToLower() == ".tif") && p.Extension.ToLower() != ".db");
                imageList = new List<ImageList>();
                imageList.Clear();
                if (!string.IsNullOrEmpty(mtxtSeach_List.Text))
                {
                    foreach (string s in lst)
                    {
                        FileInfo info = files.Where(p => p.Name.Contains(s)).FirstOrDefault();
                        if (info != null)
                        {
                            ImageList model = new ImageList();
                            model.Name = info.Name;
                            model.PathFull = info.FullName;
                            model.pathImage = Image.FromFile(info.FullName);
                            model.PartNo = s;
                            imageList.Add(model);
                        }
                    }
                }
                else
                {
                    foreach (FileInfo info in files)
                    {
                        ImageList model = new ImageList();
                        model.Name = info.Name;
                        model.PathFull = info.FullName;
                        model.pathImage = Image.FromFile(info.FullName);
                        model.PartNo = info.Name.Split('.')[0];
                        imageList.Add(model);
                    }
                }

                searchControl1.Properties.Items.Clear();
                this.gridControl1.BeginUpdate();
                this.gridControl1.DataSource = imageList;
                this.gridControl1.EndUpdate();
                imageSlider1.Images.Clear();
                for (int i = 0; i < layoutView1.RowCount; i++)
                {
                    byte[] bytes = BitmapToBytes((Bitmap)layoutView1.GetRowCellValue(i, "pathImage"));
                    this.imageSlider1.Images.Add(Image.FromStream(BytesToStream(bytes)));
                    searchControl1.Properties.Items.Add(layoutView1.GetRowCellValue(i, "PartNo").ToString());
                }
            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message);

            }
            
        }
        public static byte[] BitmapToBytes(Bitmap bitmap) 
        {
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 
            byte[] buffer = ms.ToArray(); ms.Close(); ms.Dispose(); return buffer; 
        }

        //To Do ......，刷新左侧imageSlider1
        private void layoutView1_Click(object sender, EventArgs e)
        {
            if (layoutView1.RowCount == 0)
                return;
            //imageSlider1控件加载图片
            int irow = layoutView1.FocusedRowHandle;
            //byte[] bytes = (byte[])layoutView1.GetRowCellValue(irow, "pathImage");
            //imageSlider1.ImageList = Image.FromStream(BytesToStream(bytes)) ;
            //this.imageSlider1.Images.Add(Image.FromStream(BytesToStream(bytes)));
            this.imageSlider1.SetCurrentImageIndex(irow,true);
            myBmp =(Bitmap)layoutView1.GetRowCellValue(irow, "pathImage");
            //imageSlider1控件图片自适应


        }
        /// 将 byte[] 转成 Stream
        public Stream BytesToStream(byte[] bytes)
        {
            Stream stream = new MemoryStream(bytes);
            return stream;
        }
        private void layoutView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            layoutView1_Click(null, null);
        }

        //切换找图路径
        private void cboxSearchType_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cboxSearchType.SelectedText)
            {
                case "生产用图库":
                    txtSearch_Path.Text = @"\\tx-fs10\tx-fs1\Engineering_drawings";
                    break;
                case "SJ_桌子":
                    txtSearch_Path.Text = @"\\tx-fs8\tx-pdd\SJ\SJR_DESK_DWG\Summary";
                    break;
                case "SJ_屏风":
                    txtSearch_Path.Text = @"\\tx-fs8\tx-pdd\SJ\SJR_PANEL_DWG\Summary";
                    break;
                case "SJ_MCG":
                    txtSearch_Path.Text = @"\\tx-fs8\tx-pdd\SJ\SJR_MCG_DWG\Summary";
                    break;
                case "标准_桌子":
                    txtSearch_Path.Text = @"\\tx-fs8\TX-PDD\SJ\STD_DESK_DWG\SUMMARY";
                    break;
                case "标准_屏风":
                    txtSearch_Path.Text = @"\\tx-fs8\TX-PDD\SJ\STD_PANEL_DWG\SUMMARY";
                    break;
                case "标准_MCG":
                    txtSearch_Path.Text = @"\\tx-fs8\TX-PDD\SJ\STD_MCG_DWG\SUMMARY";
                    break;
                case "OEM":
                    txtSearch_Path.Text = @"\\tx-fs8\tx-fs\TX-Department\TX-MFG\PPC\Planning\ppc11\OEM图纸\TIF格式";
                    break;
                case "ItemSpec":
                    txtSearch_Path.Text = @"\\tx-fs8\tx-pdd\ISP&AVL\ISP_常用";
                    break;
                default:
                    break;
            }
        }

        private void txtSearch_Path_KeyDown(object sender, KeyEventArgs e)
        {
            cboxSearchType.Text = "";
        }

        //To Do ......，
        #region 图片放大缩小平移，平移有问题

        private bool isMouseDown = false;
        private Point mouseOffset;

        private void panelImage_MouseWheel(object sender, MouseEventArgs e)
        {
            //double step = 1.2;
            //if (e.Delta > 0)
            //{
            //    if (imageSlider1.Height >= Screen.PrimaryScreen.Bounds.Height * 10)
            //        return;
            //    imageSlider1.Height = (int)(imageSlider1.Height * step);
            //    imageSlider1.Width = (int)(imageSlider1.Width * step);

            //    int px = Cursor.Position.X - imageSlider1.Location.X;
            //    int py = Cursor.Position.Y - imageSlider1.Location.Y;
            //    int px_add = (int)(px * (step - 1.0));
            //    int py_add = (int)(py * (step - 1.0));
            //    imageSlider1.Location = new Point(imageSlider1.Location.X - px_add, imageSlider1.Location.Y - py_add);
            //    Application.DoEvents();
            //}
            //else
            //{
            //    imageSlider1.Height = (int)(imageSlider1.Height / step);
            //    imageSlider1.Width = (int)(imageSlider1.Width / step);

            //    int px = Cursor.Position.X - imageSlider1.Location.X;
            //    int py = Cursor.Position.Y - imageSlider1.Location.Y;
            //    int px_add = (int)(px * (1.0 - 1.0 / step));
            //    int py_add = (int)(py * (1.0 - 1.0 / step));
            //    imageSlider1.Location = new Point(imageSlider1.Location.X + px_add, imageSlider1.Location.Y + py_add);
            //    Application.DoEvents();
            //}
        }

        private void imageSlider1_MouseWheel(object sender, MouseEventArgs e)
        {
            //double step = 1.2;
            //if (e.Delta > 0)
            //{
            //    if (imageSlider1.Height >= Screen.PrimaryScreen.Bounds.Height * 10)
            //        return;
            //    imageSlider1.Height = (int)(imageSlider1.Height * step);
            //    imageSlider1.Width = (int)(imageSlider1.Width * step);

            //    int px = Cursor.Position.X - imageSlider1.Location.X;
            //    int py = Cursor.Position.Y - imageSlider1.Location.Y;
            //    int px_add = (int)(px * (step - 1.0));
            //    int py_add = (int)(py * (step - 1.0));
            //    imageSlider1.Location = new Point(imageSlider1.Location.X - px_add, imageSlider1.Location.Y - py_add);
            //    Application.DoEvents();
            //}
            //else
            //{
            //    imageSlider1.Height = (int)(imageSlider1.Height / step);
            //    imageSlider1.Width = (int)(imageSlider1.Width / step);

            //    int px = Cursor.Position.X - imageSlider1.Location.X;
            //    int py = Cursor.Position.Y - imageSlider1.Location.Y;
            //    int px_add = (int)(px * (1.0 - 1.0 / step));
            //    int py_add = (int)(py * (1.0 - 1.0 / step));
            //    imageSlider1.Location = new Point(imageSlider1.Location.X + px_add, imageSlider1.Location.Y + py_add);
            //    Application.DoEvents();
            //}

            int x = e.Location.X;
            int y = e.Location.Y;
            int ow = imageSlider1.Width;
            int oh = imageSlider1.Height;
            int VX, VY;
            if (e.Delta > 0)
            {
                imageSlider1.Width += zoomStep;
                imageSlider1.Height += zoomStep;
                 
                PropertyInfo pInfo = imageSlider1.GetType().GetProperty("ClientRectangle");
                Rectangle rect = (Rectangle)pInfo.GetValue(imageSlider1, null);

                imageSlider1.Width = rect.Width;
                imageSlider1.Height = rect.Height;
            }
            if (e.Delta < 0)
            {
                if (myBmp != null)
                {
                    if (imageSlider1.Width < myBmp.Width / 10)
                        return;

                    imageSlider1.Width -= zoomStep;
                    imageSlider1.Height -= zoomStep;
                    PropertyInfo pInfo = imageSlider1.GetType().GetProperty("ClientRectangle");
                    Rectangle rect = (Rectangle)pInfo.GetValue(imageSlider1, null);
                    if (rect.Height == 0)
                    {
                        imageSlider1.Width = 40;
                        imageSlider1.Height = 20;
                    }
                    else
                    {
                        imageSlider1.Width = rect.Width;
                        imageSlider1.Height = rect.Height;
                    }
                }
            }

            VX = (int)((double)x * (ow - imageSlider1.Width) / ow);
            VY = (int)((double)y * (oh - imageSlider1.Height) / oh);
            imageSlider1.Location = new Point(imageSlider1.Location.X + VX, imageSlider1.Location.Y + VY);
        }

        private void imageSlider1_MouseMove(object sender, MouseEventArgs e)
        {
            //if (isMouseDown)
            //{
            //    int left = imageSlider1.Left + e.X - mouseOffset.X;
            //    int top = imageSlider1.Top + e.Y - mouseOffset.Y;
            //    imageSlider1.Location = new Point(left, top);
            //}
            ////不能在MouseMove事件中关闭，因为打开时间
            //if (fm != null)
            //{
            //    //没调好不起作用
            //    timer1.Start();
            //    timer1.Stop();
            //}

            //imageSlider1.Focus();//
            //if (isMove)
            //{
            //    int x, y;
            //    int moveX, moveY;
            //    moveX = Cursor.Position.X - mouseDownPoint.X;
            //    moveY = Cursor.Position.Y - mouseDownPoint.Y;
            //    x = imageSlider1.Location.X + moveX;
            //    y = imageSlider1.Location.Y + moveY;
            //    imageSlider1.Location = new Point(x, y);
            //    mouseDownPoint.X = Cursor.Position.X;
            //    mouseDownPoint.Y = Cursor.Position.Y;
            //}

            imageSlider1.Focus();
            if (isMove)
            {
                int x, y;
                int moveX, moveY;
                moveX = Cursor.Position.X - mouseDownPoint.X;
                moveY = Cursor.Position.Y - mouseDownPoint.Y;
                x = imageSlider1.Location.X + moveX;
                y = imageSlider1.Location.Y + moveY;
                imageSlider1.Location = new Point(x, y);
                mouseDownPoint.X = Cursor.Position.X;
                mouseDownPoint.Y = Cursor.Position.Y;
            }
        }

        private void imageSlider1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMove = false;
            }

        }

        private void imageSlider1_MouseDown(object sender, MouseEventArgs e)
        {
            //if (e.Button == MouseButtons.Right)//右键（右击）
            //{
            //    imageSlider1.Width = panelImage.Width;
            //    imageSlider1.Height = panelImage.Height;
            //    imageSlider1.Location = new Point(0, 0);
            //}
            //if (e.Button == MouseButtons.Left)
            //{
            //    mouseDownPoint.X = Cursor.Position.X;
            //    mouseDownPoint.Y = Cursor.Position.Y;
            //    isMove = true;
            //    imageSlider1.Focus();//
            //}

            if (e.Button == MouseButtons.Left)
            {
                mouseDownPoint.X = Cursor.Position.X;
                mouseDownPoint.Y = Cursor.Position.Y;
                isMove = true;
            }
        }
        private void panelImage_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseDownPoint.X = Cursor.Position.X;
                mouseDownPoint.Y = Cursor.Position.Y;
                isMove = true;
            }
        }

        private void panelImage_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMove = false;
            }

        }

        private void panelImage_MouseMove(object sender, MouseEventArgs e)
        {
            panelImage.Focus();
            if (isMove)
            {
                int x, y;
                int moveX, moveY;
                moveX = Cursor.Position.X - mouseDownPoint.X;
                moveY = Cursor.Position.Y - mouseDownPoint.Y;
                x = imageSlider1.Location.X + moveX;
                y = imageSlider1.Location.Y + moveY;
                imageSlider1.Location = new Point(x, y);
                mouseDownPoint.X = Cursor.Position.X;
                mouseDownPoint.Y = Cursor.Position.Y;
            }
        }
        #endregion

        #region 实例化标准功能

        public override void DoView(IButtonInfo sender)
        {
            sbtnView_Click(null, null);
            base.DoView(sender);
        }

        private void 切换查找路径ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sbtnGetPath_Click(null, null);
        }

        private void 隐藏选项区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelControl_Top.Height = 0;
        }

        private void 显示选项区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelControl_Top.Height = 60;
        }

        private void 隐藏缩略图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Width;
            gridControl1.Visible = false;
        }

        private void 显示缩略图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Width - 210;
            gridControl1.Visible = true;
        }

        #endregion

        #region 图片大小自适应，待优化

        private void imageDisplayAdjust(ImageSlider imgSlider)
        {
            if (imageSlider1.CurrentImage != null)
            {


                Bitmap bmp = new Bitmap(imageSlider1.CurrentImage);

                if (bmp.Width < imgSlider.Width)
                {
                    imgSlider.LayoutMode = DevExpress.Utils.Drawing.ImageLayoutMode.MiddleCenter;
                }
                else
                {
                    imgSlider.LayoutMode = DevExpress.Utils.Drawing.ImageLayoutMode.ZoomInside;
                }
            }
        }

        private void imageSlider1_ImageChanged(object sender, DevExpress.XtraEditors.Controls.ImageChangedEventArgs e)
        {
            //切换显示模式时，画面有闪烁，待解决
            //已尝试用CurrentImageIndexChanged、GetImage、CanGetNextPrevImage事件，均未解决
            imageDisplayAdjust(imageSlider1);
        }

        private void imageSlider1_CanGetNextPrevImage(object sender, CanGetNextPrevImageEventArgs e)
        {
            imageDisplayAdjust(imageSlider1);
        }

        #endregion

        #region 测试用代码

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void gridControlDataBinding_ThroughCondition()
        {

            //从数据库加载图片
            //DataTable dt = dsHelper.GetBZPicList();
            //if (dt.Rows.Count > 0)
            //{
            //    for (int i = 0; i < dt.Rows.Count; i++)
            //    {
            //        //将图片路径转换成image对象
            //        this.imageSlider1.Images.Add(((System.Drawing.Image)(Image.FromFile("文件路径"))));
            //    }
            //}

            //从指定路径加载图片
            var path = txtSearch_Path.Text;

            var files = new DirectoryInfo(path).GetFiles().Where(p => p.Extension.ToLower() == ".jpg");
            var data = files.Select(d =>
            {
                //this.imageSlider1.Images.Add(Image.FromFile(d.FullName));
                return new { Name = d.Name, Image = Image.FromFile(d.FullName), Paths = d.FullName };
            });

            this.gridControl1.BeginUpdate();
            this.gridControl1.DataSource = data;
            this.gridControl1.EndUpdate();
        }

        private void searchControl1_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(searchControl1.Text))
            {
                this.gridControl1.BeginUpdate();
                this.gridControl1.DataSource = imageList;
                this.gridControl1.EndUpdate();
                imageSlider1.Images.Clear();
                for (int i = 0; i < layoutView1.RowCount; i++)
                {
                    byte[] bytes = BitmapToBytes((Bitmap)layoutView1.GetRowCellValue(i, "pathImage"));
                    this.imageSlider1.Images.Add(Image.FromStream(BytesToStream(bytes)));
                }
            }
            else
            {
                List<ImageList> _lst = imageList.Where(p => p.PartNo == searchControl1.Text).ToList();
                if (_lst.Count != 0)
                {
                    this.gridControl1.BeginUpdate();
                    this.gridControl1.DataSource = _lst;
                    this.gridControl1.EndUpdate();
                }
                else
                {
                    this.gridControl1.BeginUpdate();
                    this.gridControl1.DataSource = null;
                    this.gridControl1.EndUpdate();
                }
                imageSlider1.Images.Clear();
                for (int i = 0; i < layoutView1.RowCount; i++)
                {
                    byte[] bytes = BitmapToBytes((Bitmap)layoutView1.GetRowCellValue(i, "pathImage"));
                    this.imageSlider1.Images.Add(Image.FromStream(BytesToStream(bytes)));
                }
            }
        }

        private void searchControl1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                
                this.gridControl1.DataSource = null;
                if (lst.Count != 0)
                {
                    List<ImageList> _lst = imageList.Where(p => p.PartNo == searchControl1.Text).ToList();
                    if (_lst.Count != 0)
                    {
                        this.gridControl1.BeginUpdate();
                        this.gridControl1.DataSource = _lst;
                        this.gridControl1.EndUpdate();
                    }
                    else
                    {
                        this.gridControl1.BeginUpdate();
                        this.gridControl1.DataSource = null;
                        this.gridControl1.EndUpdate();
                    }
                    imageSlider1.Images.Clear();
                    for (int i = 0; i < layoutView1.RowCount; i++)
                    {
                        byte[] bytes = BitmapToBytes((Bitmap)layoutView1.GetRowCellValue(i, "pathImage"));
                        this.imageSlider1.Images.Add(Image.FromStream(BytesToStream(bytes)));
                    }
                }
            }
        }



        //图纸浏览模式
        private void gridControlDataBinding_WholePath()
        {
            //从指定路径加载图片
            var path = txtSearch_Path.Text;

            //要求支持【jgp及tif】两种格式
            var files = new DirectoryInfo(path).GetFiles().Where(p => p.Extension.ToLower() != ".db");
            var data = files.Select(d =>
            {
                //为防止数据量过大，导致内存溢出或加载时间过长，可采用加载缩略图模式
                return new { Name = d.Name, Image = Image.FromFile(d.FullName), Paths = d.FullName };
            });

            this.gridControl1.BeginUpdate();
            this.gridControl1.DataSource = data;
            this.gridControl1.EndUpdate();
        }




        //    private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
        //    {
        //        //ToolTipController与GridControl的连用
        //        //鼠标指向表格时 显示更多信息 toolTipController1
        //        //https://www.it610.com/article/1296112.htm

        //        if (e.SelectedControl != imageSlider1) return;
        //        ToolTipControlInfo info = null;

        //        object o = "AA";
        //        StringBuilder sb = new StringBuilder();

        //        sb.AppendLine("行数据基本信息:");
        //        sb.AppendFormat("{0}:{1}\r\n", "1", "2");
        //        info = new ToolTipControlInfo(o, sb.ToString());

        //        if (info != null)
        //        {
        //            e.Info = info;
        //        }
        //    }

        #endregion

    }
}